package com.airline.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.airline.beans.Employee;
import com.airline.connection.AirlineSystemServiceProxy;
import com.airline.form.UpdateEmployeeForm;
import com.airline.form.UpdateEmployeeIDForm;

public class EmployeeIDAction extends DispatchAction {

	AirlineSystemServiceProxy proxy = new AirlineSystemServiceProxy();

	public ActionForward updateId(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		UpdateEmployeeForm empform = new UpdateEmployeeForm();
		String empid = request.getParameter("empid");

		Employee emp = proxy.getEmployee(empid);

		if (null == emp) {

		((UpdateEmployeeIDForm)	(form)).setError("No Employee with the ID " + empid + " exists");
			return mapping.findForward("failure");
		}

		empform.setEmp(emp);

		request.getSession().setAttribute("updateEmployeeForm", empform);
		
		Employee loginEmp = (Employee) request.getSession().getAttribute("employee");
		
		if(empid.equalsIgnoreCase(loginEmp.getPersonID()))
		
			request.getSession().setAttribute("employee", emp);
		
		return mapping.findForward("update");

	}

}
